import { request } from '@inbiz/utils';
// import InbizConfig from 'InbizConfig'
// const Mock = require('/Users/zhujiaqing/.nvm/versions/node/v14.15.3/lib/node_modules/mockjs');

const version = InbizConfig.API_VERSION;

export async function getNewsCategory(params: News.NewsCategoryParams) {
  return request(`/inbiz/api/services/cms/v${version}/cms/cmsCategoryList`, {
    params: {
      ...params,
      categoryType: 1,
      pageSize: 999999,
      pageIndex: 1,
    },
  });
}

export async function getNewsList(params: News.NewsListParams) {
  return request(`/inbiz/api/services/cms/v${version}/cms/contentList`, {
    params: {
      ...params,
      contentType: 1,
    },
  });
}

export async function getDetail(params: News.DetailParams) {
  return request(
    `/inbiz/api/services/cms/v${version}/cms/${params.id}/detailContentInfo`,
    {
      params,
    },
  );
}

// 获取实体所有统计数据
export async function getCounts(params: { entitylds: string[]; }) {
  return request(
    `/inbiz/api/common/StatisticManager/GetAllByEntityIds`,
    {
      params: {
        entityIds: params?.entitylds?.join(','),
        module: 'km',
        category: 'cms.news',
      }
    },
  );
}

// 增加统计数据
export async function addCounts(params: { entityld: string; }) {
  return request(
    `/inbiz/api/common/StatisticManager/Add`,
    {
      method: 'POST',
      data: {
        module: 'km',
        category: 'cms.news.view',
        entityId: params?.entityld,
        type: 0,
      }
    },
  );
}